package com.qimo.zzy.service;

import com.qimo.zzy.dao.AddressDao;
import com.qimo.zzy.entity.ResultEntity;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class AddressService {
    private static final Logger logger = LoggerFactory.getLogger(UserService.class);//日志。getLogger需要传入当前的类名

    @Resource
    AddressDao addressDao;

    /**
     * 获取所有地址方法
     *
     * @param uid
     * @return
     */
    public String getAddressList(int uid) {
        try {
            return ResultEntity.success(addressDao.getAddressList(uid));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 删除用户地址
     *
     * @param addressId
     * @return
     */
    public String delAddress(int addressId) {
        try {
            return ResultEntity.success(addressDao.delAddress(addressId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 修改用户地址
     *
     * @param addressId
     * @param receiver
     * @param province
     * @param city
     * @param county
     * @param address
     * @param areaCode
     * @param cellPhone
     * @param fixedPhone
     * @param postCode
     * @param tag
     * @param isDefault
     * @return
     */
    public String chanceAddress(int addressId, String receiver, String province, String city, String county, String address, String areaCode, String cellPhone, String fixedPhone, String postCode, String tag, int isDefault) {
        try {
            return ResultEntity.success(addressDao.chanceAddress(addressId, receiver, province, city, county, address, areaCode, cellPhone, fixedPhone, postCode,
                    tag, isDefault));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 新增用户地址
     * @param uid
     * @param receiver
     * @param province
     * @param city
     * @param county
     * @param address
     * @param areaCode
     * @param cellPhone
     * @param fixedPhone
     * @param postCode
     * @param tag
     * @param isDefault
     * @return
     */
    public String addAddress(int uid, String receiver, String province, String city, String county, String address, String areaCode, String cellPhone, String fixedPhone, String postCode, String tag, int isDefault) {
        try {
            return ResultEntity.success(addressDao.addAddress(uid, receiver, province, city, county, address, areaCode, cellPhone, fixedPhone, postCode,
                    tag, isDefault));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }


}